package com.rzj.book.dao;

import com.rzj.book.en.Role;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @ClassName IRoleDao
 * @Description TODO
 * @Author Administrator
 * @Date 2020/5/17 19:10
 * @Version 1.0
 */
@Mapper
public interface IRoleDao {

    @Select("select * from role where roleId = #{roleId}")
    @Results({
            @Result(id=true,column="roleId",property="roleId"),
            @Result(column="name",property="name"),
            @Result(column="roleId",property="menus",many = @Many(select = "com.rzj.book.dao.IMenuDao.findMenuListByRoleId",fetchType = FetchType.LAZY)),
            @Result(column="roleId",property="emps",many=@Many(select="com.rzj.book.dao.IEmpDao.getEmpListByRoleId",fetchType = FetchType.LAZY))
    })
    Role getRoleById(Integer roleId);

    @Select("select * from role")
    List<Role> getRoleList();

    @Select(" select r.* from role r LEFT JOIN emp_role er on er.roleId = r.roleId " +
            " left JOIN emp e on e.empId = er.empId " +
            " where e.empId = #{empId} ")
    List<Role> getRoleListByEmpId(Integer empId);
}
